package aes.gui;

import java.awt.CardLayout;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSeparator;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

import aes.general.AdminControl;

/**
 * The Class AdminViewExamsPanel. This panel shows the exams for the admin
 */
public class AdminViewExamsPanel extends JPanel {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private JPanel jp;
	private JLabel l1;
	private JButton b1; 
	private JSeparator separator;
	
	private DefaultTableModel model;
	private ArrayList<String> exams = new ArrayList<String>();
	private JTable t;
	private JPanel panel;
	
	
	/**
	 * Create the panel.
	 * 
	 * @param contentPane
	 *            the content pane
	 */
	public AdminViewExamsPanel(JPanel contentPane) {
		this.jp = contentPane;
		setLayout(null);
		initialize();
	}

	/**
	 * Initialize.
	 */
	private void initialize() {
		
		l1 = new JLabel("Exams");
		l1.setFont(new Font("Tempus Sans ITC", Font.BOLD, 21));
		l1.setBounds(277, 11, 86, 29);
		add(l1);
		
		separator = new JSeparator();
		separator.setBounds(10, 43, 620, 2);
		add(separator);
		try {
			Thread.sleep(500);
		} catch (InterruptedException e1) {
			e1.printStackTrace();
		}
		exams = AdminControl.getExams();

		String col[] = {"ExamId","Teacher ID","Creation Date", "Subject"};
		String data[][] = {{}};
		model = new DefaultTableModel(data,col);
		int j = 0;
		for(int i=0;i<exams.size();i++,j++)
			model.insertRow(j,new Object[]{exams.get(i),exams.get(++i),exams.get(++i),exams.get(++i)});
		model.removeRow(j);
		
		b1 = new JButton("Back");
		b1.setBounds(274, 405, 91, 23);
		add(b1);
		
		panel = new JPanel();
		panel.setBounds(20, 65, 591, 312);
		add(panel);
		panel.setLayout(null);
		
		t = new JTable(model);
		t.setFont(new Font("Tahoma", Font.BOLD, 12));
		t.setBounds(117, 93, 405, 284);
		JScrollPane sc = new JScrollPane(t);
		sc.setBounds(69, 5, 452, 283);
		panel.add(sc);
		b1.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				exams.clear();
				CardLayout cl = (CardLayout) (jp.getLayout());
				cl.show(jp, "AdminMain");	
			}
		});
		

	}
}
